home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: netcom.com!smryan
- From: smryan@netcom.com (@#$%!?!)
- Subject: Re: ellipse parameter of printf()
- Message-ID: <smryanDpoLLF.IwJ@netcom.com>
- Organization: The Programmer formerly known as S M Ryan
- X-Newsreader: TIN [version 1.2 PL1]
- References: <4kh5p8$lm4@dewey.csun.edu>
- Date: Thu, 11 Apr 1996 04:53:39 GMT
- Sender: smryan@netcom3.netcom.com
-
- : In stdio.h,the parameter printf() is '...',what is that means,
- : how compiler treat this ?
-
- In a function declaration, '...' means 'and an indefinite number of
- additional parameters.'
-
- printf(char*,...)
-
- takes a char* and an indefinite number of additional parameters.
-
- fprintf(FILE*,char*,...)
-
- takes a FILE*, a char*, and an indefinite number of additional parameters.
-
-
- The additional parameters are called varargs, from <varargs.h>, the old
- way for a function (like printf) to access those additional parameters.
- The ANS-C method uses <stdarg.h>.
-
- With varargs, the compiler has no types to check the actual parameters
- to, nor does the language definition provide any mechanism to pass the
- actual number and types of parameter. The called function must use
- earlier entries in the parameter list or some other technique to decide
- how many parameters are present and what their types are. The caller
- must obey the calling conventions--there is in general no standard way
- for the compiler to enforce such conventions.
-
- In particular, printf assumes the number and types of parameters based
- on the format specifications in the first first parameter. In
-
- printf("%s-%d-%f\n",
-
- printf will assume it has three additional parameters, the first being
- char*, the second int, the third double. (Float and short parameters are
- automatically converted to doubles and ints by the compiler.)
-
- --
- The Queen, amused, in quiet power, | smryan@netcom.com PO Box 1563
- will draw the son to darkenned bower. | Cupertino, California
- Her face is fair, her fragrance rare, | (xxx)xxx-xxxx 95015
- with woven webs for wayward flower. | I don't use no smileys
-